﻿{extend name="public:base" /}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <a href="{:url('doArticle')}" type="button" class="btn btn-primary btn-lg">新增</a>

                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">


                    <form class="row" method="get">
                        <div class="col-sm-2 m-b-xs">
                            <select class="form-control-sm form-control input-s-sm inline one_type_id" name="one_type_id">
                                <option value="0">请选择一级分类</option>
                                {volist name="type_list" id="vo"}
                                <option value="{$vo.id}" {if ($vo['id'] == input('one_type_id'))}selected{/if}>{$vo.name}</option>
                                {/volist}
                            </select>
                        </div>

                        <div class="col-sm-2 m-b-xs">
                            <select class="form-control-sm form-control input-s-sm inline two_type_id" name="two_type_id">
                                <option value="0">请选择二级分类</option>
                                {volist name="two_type_list" id="vo"}
                                <option value="{$vo.id}" {if ($vo['id'] == input('two_type_id'))}selected{/if}>{$vo.name}</option>
                                {/volist}
                            </select>
                        </div>

                        <div class="col-sm-2 m-b-xs">
                            <select class="form-control-sm form-control input-s-sm inline" name="is_banner">
                                <option value="-1">请选择文章类型</option>
                                <option value="0" {if (input('is_banner') === '0')}selected{/if}>非banner文章</option>
                                <option value="1" {if (input('is_banner') === '1')}selected{/if}>banner文章</option>
                            </select>
                        </div>

                        <div class="col-sm-3">
                            <div class="input-group">
                                <input placeholder="请输入搜索内容" type="text" name="name" class="form-control form-control-sm" value="{:input('name')}">
                                <span class="input-group-append">
                                    <button type="submit" class="btn btn-sm btn-primary" >搜索!</button>
                                </span>
                            </div>
                        </div>
                    </form>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>标题</th>
                                <th>所属分类</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.id}</td>
                                <td>{$vo.title}</td>
                                <td>{$vo.one_type_id|getTypeName} - {$vo.two_type_id|getTypeName}</td>
                                <td>{$vo.create_time|time_format}</td>
                                <td class="project-actions">
                                    <a href="{:url('doArticle', ['id' => $vo['id']])}" class="btn btn-white btn-sm"><i class="fa fa-edit"></i> 编辑 </a>
                                    <a href="{:url('delArticle', ['id' => $vo['id']])}" class="btn btn-white btn-sm ajax-del"><i class="fa fa-trash-o"></i> 删除 </a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {$list->render()}
                    </div>

                </div>
            </div>
        </div>

    </div>
</div>

{/block}

{block name="js"}

<script>
    $('.one_type_id').change(function () {
        var one_type_id = $(this).val();
        var url = "{:url('getTwoTypeList')}";

        $.post(url, {
            pid: one_type_id
        }, function (res) {
            var option = "<option value='0'>请选择二级分类</option>";
            if (res.result == 1) {
                var list = res.data;
                list.forEach(function (val) {
                    option += "<option value='" + val.id + "'>" + val.name + "</option>";
                })
            }
            $('.two_type_id').html(option);
        }, 'json')
    });
</script>

{/block}